{% extends "base.html" %}

{% block content %}

<h2>简易博客</h2>
  <p class="nav">
    欢迎 {{ current_user.username }} |
    <a href="/logout">登出</a> |
    <a href="/create">写文章</a>
  </p>
  <ul>
    {% for post in posts %}
    <li>
      <a class="box" href="{{ url_for('post', post_id=post.id) }}">{{ post.title }}
        <span class="t1">{{ post.created_at }}</span>
        <span class="t1">标签：
          {% for tag in post.tags %}
          <span>{{ tag.name }}</span>
          {% endfor %}
        </span>
        <span class="t1">分类：{{ post.category.name }}</span>
      </a>
    </li>
    {% endfor %}
  </ul>

  <div class="pagination">
    {% if pagination.page > 1 %}
    <a href="{{ url_for('admin_index', page=1, per_page=per_page) }}">首页</a>
    {% endif %}

    {% if pagination.has_prev %}
    <a href="{{ url_for('admin_index', page=pagination.prev_num, per_page=per_page) }}">« 上一页</a>
    {% endif %}

    <span>第 {{ pagination.page }} 页 / 共 {{ pagination.pages }} 页</span>
    {% if pagination.has_next %}
    <a href="{{ url_for('admin_index', page=pagination.next_num, per_page=per_page) }}">下一页 »</a> 
    {% endif %} 
    {% if pagination.page < pagination.pages %} 
    <a href="{{ url_for('admin_index', page=pagination.pages, per_page=per_page) }}">末页</a>
    {% endif %}
  </div>

  <form method="post" action="{{ url_for('go_to_page') }}">
    <label>跳转到页：</label>
    <input type="number" name="page" min="1" max="{{ pagination.pages }}">
    <label>每页条数：</label>
    <select name="per_page">
      <option value="5"  {% if per_page==5  %}selected{% endif %}>5</option>
      <option value="10" {% if per_page==10 %}selected{% endif %}>10</option>
      <option value="20" {% if per_page==20 %}selected{% endif %}>20</option>
    </select>
    <input type="hidden" name="from_admin" value="{{ '1' if is_admin else '0' }}">
    <button type="submit">Go</button>
  </form>

{% endblock %}